class code6 {
    //后缀表达式求值
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String s:tokens) {
            if(options(s)) {
                int t1 = stack.pop();
                int t2 = stack.pop();
                if(s.equals("+")) {
                    stack.push(t1+t2);
                } else if(s.equals("-")) {
                    stack.push(t2-t1);
                } else if(s.equals("*")) {
                    stack.push(t1*t2);
                } else {
                    stack.push(t2/t1);
                }
            } else {
                //字符串转为数字
                int val = Integer.valueOf(s);
                stack.push(val);
            }
        }
        return stack.pop();
    }

    public boolean options(String s) {
        if(s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/")) {
            return true;
        } else {
            return false;
        }
    }
}